/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entity.DomainList;
import Entity.ServiceOffered;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author THANHDAT
 */
public class DAO_ServiceOffered {

    List<ServiceOffered> lstOffer;

    public DAO_ServiceOffered() {
    }

    public List<ServiceOffered> showServiceOffered() {
        lstOffer = new ArrayList<ServiceOffered>();
        String query = "select * from tblServiceOffered";
        try {
            Statement st = DAO_Connect.getConnection().createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                int offerId = rs.getInt(1);
                int domainId = rs.getInt(2);
                String name = rs.getString(3);
                float price = rs.getFloat(4);
                String image = rs.getString(5);
                String des = rs.getString(6);
                ServiceOffered offer = new ServiceOffered(offerId, domainId, name, price, image, des);
                lstOffer.add(offer);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lstOffer;
    }

    public List<ServiceOffered> getOfferedByDomainId(int offeId) {
        lstOffer = new ArrayList<ServiceOffered>();
        String query = "select * from tblServiceOffered where domainID = " + offeId;
        try {
            Statement st = DAO_Connect.getConnection().createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                int proId = rs.getInt(1);
                int domainId = rs.getInt(2);
                String name = rs.getString(3);
                float price = rs.getFloat(4);
                String image = rs.getString(5);
                String des = rs.getString(6);
                ServiceOffered offer = new ServiceOffered(proId, domainId, name, price, image, des);
                lstOffer.add(offer);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lstOffer;
    }

    public ServiceOffered getServiceOfferedById(int offerId) {
        String query = "select * from tblServiceOffered where proID = " + offerId;
        ServiceOffered offer = new ServiceOffered();
        try {
            Statement st = DAO_Connect.getConnection().createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {                
                offer.setOfferId(rs.getInt(1));
                offer.setDomainId(rs.getInt(2));
                offer.setName(rs.getString(3));
                offer.setPrice(rs.getFloat(4));
                offer.setImage(rs.getString(5));
                offer.setDescription(rs.getString(6));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return offer;
    }
}
